package com.easa.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;

@Controller
public class MainController {

    @RequestMapping("/")
    public String gotoIndexPage(){
        return "index";
    }

    @RequestMapping("/classmsg.do")
    public String gotoClassmsgPage(){
        return "classmsg";
    }

    @RequestMapping("/laboratorymsg.do")
    public String gotoLaboratorymsgPage(){
        return "laboratorymsg";
    }

    @RequestMapping("/login.do")
    public String gotoLogin(){
        return "login";
    }

    /*主页跳转*/
    @RequestMapping("/logout.do")
    public String logout(HttpServletRequest request, HttpServletResponse resp) throws IOException {

        resp.setContentType("text/html;charset=utf-8");
        //使Session失效
        HttpSession sess = request.getSession();
        sess.invalidate();
        //重定向到首页
        resp.getWriter().write("<SCRIPT> alert('注销成功');</SCRIPT>");
        return "login";
    }

    //跳转到详细页
    @RequestMapping("/classDetailUrl.do")
    public ModelAndView classDetailUrl(HttpServletRequest request){

        ModelAndView mav = new ModelAndView();
        String cid = request.getParameter("cid");
        System.out.println("cid:"+cid);
        mav.setViewName("classDetail"); //返回的文件名
        mav.addObject("cidx",cid);
        return mav;
    }

    //跳转到详细页
    @RequestMapping("/laboratoryDetailUrl.do")
    public ModelAndView laboratoryDetailUrl(HttpServletRequest request){

        ModelAndView mav = new ModelAndView();
        String lid = request.getParameter("lid");
        System.out.println("lid:"+lid);
        mav.setViewName("laboratoryDetail"); //返回的文件名
        mav.addObject("lidx",lid);
        return mav;
    }

    //跳转到添加实验室信息页面
    @RequestMapping("/addlaboratoryUrl.do")
    public String gotoAddlaboratory(){
        return "addlaboratory";
    }

    //跳转到教学日历管理页面
    @RequestMapping("/semestermsgUrl.do")
    public String semestermsgUrl(){
        return "semestermsg";
    }

    //跳转到添加学期页面
    @RequestMapping("/addSemesterUrl.do")
    public String addSemesterUrl(){
        return "addSemester";
    }

    //跳转到教学日历管理页面
    @RequestMapping("/teachermsgUrl.do")
    public String teachermsgUrl(){
        return "teachermsg";
    }

    //跳转到添加教师页面
    @RequestMapping("/addTeacherUrl.do")
    public String addTeacherUrl(){
        return "addTeacher";
    }

    //跳转到详细页
    @RequestMapping("/updateTeacherUrl.do")
    public ModelAndView updateTeacherUrl(HttpServletRequest request){

        ModelAndView mav = new ModelAndView();
        String tid = request.getParameter("tid");
        System.out.println("tid:"+tid);
        mav.setViewName("updateTeacher"); //返回的文件名
        mav.addObject("tidx",tid);
        return mav;
    }

}
